<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 文件选择框 -->
    <input type="file" name="" id="">
    <img src="" alt="">
    <script>
        // 找对象
        let ipt = document.querySelector('input')
        let img = document.querySelector('img')
        // 给input注册change事件
        ipt.onchange = function(e) {
            // 获取上传的文件对象
            let file = e.target.files[0]
            console.log(file);
            // 通过 window.URL.createObjectURL(file) -> 文件的临时预览
            let url = window.URL.createObjectURL(file)
            img.src = url
        }
    </script>
</body>
</html>